using TestCases.CompareAssert.Core.Comparers.Interfaces;
using TestCases.CompareAssert.Core.Interfaces;

namespace TestCases.CompareAssert.Core.Comparers.Basic
{
    public class NullComparer : IObjectComparer
    {
        private static readonly NullComparer _instance = new NullComparer();

// Explicit static constructor to tell C# compiler not to mark type as beforefieldinit
// ReSharper disable EmptyConstructor
        static NullComparer()
// ReSharper restore EmptyConstructor
        {
        }

        private NullComparer()
        {
        }

        public static NullComparer Instance
        {
            get { return _instance; }
        }        
        

        public string Name
        {
            get { return "NullComparer"; }
        }

        public IResultBuilder Compare(ICompareContext context)
        {
            if (context.LValue == null && context.RValue == null)
            {
                return this.IsEquals(context).
                    Message("<{LPath}> and <{RPath}> both are nulls [{LValue} == {RValue}].");
            }

            if (context.LValue != null && context.RValue == null)
            {
                return this.IsNotEquals(context).
                    Message("<{LPath}> is not null, but <{RPath}> is null [{LValue} != {RValue}].");
            }

            if (context.LValue == null && context.RValue != null)
            {
                return this.IsNotEquals(context).
                    Message("<{LPath}> is null, but <{RPath}> is not null [{LValue} != {RValue}].");
            }
            return this.IsNotApplicable(context).
                Message("<{LPath}> and <{RPath}> are not nulls [{LValue} != {RValue}].");
        }
    }
}